using System;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using THSLib;using THSERP.BaseProvider;
using THSERP.BusinessEntities;
namespace THSERP.Modules.Invoice
{
    public class InvoiceEntities : ERPModuleEntities
    {
        #region Declare Constant
        public readonly static String strARInvoicesObjectName = THSUtil.GetTableNameFromBusinessObjectType(typeof(ARInvoicesInfo));

        public readonly static String strARInvoiceItemsObjectName = THSUtil.GetTableNameFromBusinessObjectType(typeof(ARInvoiceItemsInfo));
        public readonly static String strGELocationsObjectName = THSUtil.GetTableNameFromBusinessObjectType(typeof(GELocationsInfo));
        public readonly static String strICProductsObjectName = THSUtil.GetTableNameFromBusinessObjectType(typeof(ICProductsInfo));
        #endregion

        #region Declare all entities variables
        private ARInvoicesInfo _aRInvoicesObject;
        private ARInvoiceItemsInfo _aRInvoiceItemsObject;

        public THSItemsEntityList<InvoiceItemsEntity> lstARInvoiceItems;

        public THSTreeList lstGELocations;
        public THSList<ICProductsInfo> lstICProducts;
        #endregion

        #region Public Properties
        public ARInvoicesInfo ARInvoicesObject
        {
            get
            {
                return _aRInvoicesObject;
            }
            set
            {
                _aRInvoicesObject = value;
            }
        }
        public ARInvoiceItemsInfo aRInvoiceItemsObject
        {
            get
            {
                return _aRInvoiceItemsObject;
            }
            set
            {
                _aRInvoiceItemsObject = value;
            }
        }

        public THSItemsEntityList<InvoiceItemsEntity> ARInvoiceItemsList
        {
            get
            {
                return lstARInvoiceItems;
            }
            set
            {
                lstARInvoiceItems = value;
            }
        }
        public THSTreeList GELocationsList
        {
            get
            {
                return lstGELocations;
            }
            set
            {
                lstGELocations = value;
            }
        }

        public THSList<ICProductsInfo> ICProductsList
        {
            get
            {
                return lstICProducts;
            }
            set
            {
                lstICProducts = value;
            }
        }
        #endregion

        #region Constructor
        public InvoiceEntities()
            : base()
        {
            _aRInvoicesObject = new ARInvoicesInfo();

            _aRInvoiceItemsObject = new ARInvoiceItemsInfo();

            lstARInvoiceItems = new THSItemsEntityList<InvoiceItemsEntity>();
            lstGELocations = new THSTreeList();
            lstICProducts = new THSList<ICProductsInfo>();
        }

        #endregion

        #region Init Main Object,Module Objects functions
        public override void InitMainObject()
        {

            MainObject = ARInvoicesObject;
        }

        public override void InitModuleObjects()
        {
            ModuleObjects.Add(strARInvoiceItemsObjectName, aRInvoiceItemsObject);
        }

        public override void InitModuleObjectList()
        {
            lstARInvoiceItems = new THSItemsEntityList<InvoiceItemsEntity>();
            //lstARInvoiceItems.InitTHSItemsEntityList(this, THSUtil.GetTableNameFromBusinessObjectType(typeof(ARInvoiceItemsInfo)));
            lstARInvoiceItems.InitTHSList(this, strARInvoicesObjectName, strARInvoiceItemsObjectName);
            lstGELocations = new THSTreeList();
            lstGELocations.InitTHSList(this,string.Empty, strGELocationsObjectName);
            lstICProducts = new THSList<ICProductsInfo>();
            lstICProducts.InitTHSList(this, string.Empty, strICProductsObjectName);
        }

        public override void InitGridControlInTHSList()
        {
            lstARInvoiceItems.InitTHSListGridControl();
            lstGELocations.InitTHSTreeListControl();
            lstICProducts.InitTHSListGridControl();
        }

        public override void SetDefaultModuleObjectsList()
        {
            try
            {
                lstARInvoiceItems.SetDefaultListAndRefreshGridControl();
                lstGELocations.SetDefaultListAndRefreshTreeListControl();
                lstICProducts.SetDefaultListAndRefreshGridControl();

            }
            catch (Exception)
            {
                return;
            }
        }

        #endregion

        #region Invalidate Module Objects functions


        public override void InvalidateModuleObjects(int iObjectID)
        {
            ARInvoiceItemsList.Invalidate(iObjectID);
        }


        #endregion

        #region Save Module Objects functions

        public override void SaveModuleObjects()
        {
            ARInvoiceItemsList.SaveItemObjects(true);
        }

        #endregion

        public override void SetValuesAfterValidateProduct(int iICProductID)
        {
            ARInvoiceItemsList.SetDefaultValuesFromProduct(iICProductID);
        }
    }
}
